/**
 * 
 */
package com.qdairlines.common;

import java.io.PrintWriter;
import java.io.StringWriter;

import org.slf4j.Logger;




/**
 * @author sunchengtao
 * @date 2016年7月11日
 * @company QingDao Airlines
 * @description 获取异常的堆栈信息
 */
public class TraceUtil {
	/**
	 * 获取一场的堆栈信息
	 * @param t
	 * @return
	 */
    public static String getTrace(Throwable t) {
        StringWriter stringWriter= new StringWriter();
        PrintWriter writer= new PrintWriter(stringWriter);
        t.printStackTrace(writer);
        StringBuffer buffer= stringWriter.getBuffer();
        return buffer.toString();
    }
    
    /**
     * 异常记录到logger中
     * @param logger
     * @param t
     */
    public static void error(Logger logger ,Throwable t) {
    	t.printStackTrace();
		logger.error(getTrace(t));
    }
}
